﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DragDropExample
{
  public partial class DraggedMoveExample : UserControl
  {
    public DraggedMoveExample()
    {
      InitializeComponent();
    }

    private void DropTarget_OnDropped(object sender, SilverlightDragDrop.DragDropEventArgs e)
    {
      var sourcetext = ((e.Source as Border).Child as TextBlock).Text;
      var targettext = (((sender as SilverlightDragDrop.DropTarget).Content as Border).Child as TextBlock).Text;
      Message.Text = String.Format("You dropped '{0}' on '{1}'", sourcetext, targettext);

      DropBorder.BorderThickness = new Thickness(1);
    }

    private void DropTarget_OnDraggedMove(object sender, SilverlightDragDrop.DragDropEventArgs e)
    {
      var droptarget = sender as SilverlightDragDrop.DropTarget;
      var position = droptarget.TransformToVisual(null).Transform(new Point());

      double l, r, t, b;
      l = r = t = b = 1;
      if (e.MousePosition.X - position.X < 15) l = 5;
      if (e.MousePosition.Y - position.Y < 15) t = 5;
      if (position.X + droptarget.ActualWidth - e.MousePosition.X < 15) r = 5;
      if (position.Y + droptarget.ActualHeight - e.MousePosition.Y < 15) b = 5;
      DropBorder.BorderThickness = new Thickness(l,t,r,b);
    }
  }
}
